package cn.app.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.app.dao.app_info.AppInfoDao;
import cn.app.entity.AppInfo;
import cn.app.service.AppInfoService;
import cn.app.utils.PageBean;
@Service
@Transactional
public class AppInfoServiceImpl implements AppInfoService {
	
	@Autowired
	private AppInfoDao appInfoDao;

	@Override
	public PageBean<AppInfo> findAppInfoByCondition(Map<String, Object> appInfoCondition) {
		//1.查询totalCount 
		Integer totalCount = appInfoDao.findAppInfoCount(appInfoCondition);
		//2:由于第一次查询,当前页的值是null所以无法强转,所以需要一个判断
		Object object = appInfoCondition.get("currentPage");
		Integer currentPage = object == null ? 1 : (Integer)object;
		//2:虽然弄出了新的currentPage,但是map中的当前页还是null
		appInfoCondition.put("currentPage", currentPage);
		//2.1创建分页工具类
		PageBean<AppInfo> pageBean = new PageBean<>(currentPage, 5, totalCount);
		//2.2讲工具类计算出的数据,再添加到map条件中
		//3:要将工具类查询出的startIndex添加到map中
		appInfoCondition.put("startIndex", pageBean.getStartIndex());
		appInfoCondition.put("pageSize", pageBean.getPageSize());
		//3.查询数据.
		List<AppInfo> appInfoList = appInfoDao.findAllByCondition(appInfoCondition);
		//4.封装到pageBean中
		pageBean.setPageList(appInfoList);
		
		return pageBean;
	}

	
	
	@Override
	public Integer findAppInfoByAPKName(String apkName) {
		Integer count = appInfoDao.findAppInfoByAPKName(apkName);
		return count;
	}



	@Override
	public Integer saveAppInfo(AppInfo appInfo) {
		return appInfoDao.saveAppInfo(appInfo);
	}



	@Override
	public AppInfo findAppInfoById(String id) {
		return appInfoDao.findAppInfoById(id);
	}



	@Override
	public Integer updateAppInfo(AppInfo appInfo) {
		return appInfoDao.updateAppInfo(appInfo);
	}



	@Override
	public String findAPKNameById(Long appid) {
		return appInfoDao.findAPKNameById(appid);
	}



	@Override
	public void updateVersionId(Long appid, Long id) {
		// TODO Auto-generated method stub
		appInfoDao.updateVersionId(appid,id);
	}
	
}
